package d0509;

public class 自定义异常 {
	
	public static void main(String[] args) {
		
		//arrayFn();
		try {
			login(null,"yc");
		} catch( EmptyException e) {
			System.out.println(e.getMessage());
			
			// 打印异常(方法调用栈)
			e.printStackTrace();
			
			// 现场处理
			// 抛出异常
		}
		
		try {
			login("zhangsan","");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
		}
		
		try {
			login("zhangsan","123");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	/**
	 *  登录
	 *  	成功
	 *  	失败
	 * 
	 */
	public static void login(String name, String pwd) throws EmptyException{
		// isEmpty 空字符串
		if(name==null || name.isEmpty()) {
			throw new EmptyException("用户名不为空!");
		}
		
		if(pwd==null || pwd.isEmpty()) {
			throw new EmptyException("密码不为空!");
		}
		
		System.out.println("登录成功!!!");
	}
	
	
	
	
	
	// NullPointerException
	public static void nullFn() {
		// 空指针(空对象)异常
		Object o = null;
		System.out.println(o);
		o.hashCode();  // 空指针异常
	}
	
	// ArrayIndexOutOfBoundsException
	public static void arrayFn() {
		// 数组越界
		int[] a = new int[10];
		System.out.println(a[10]);
	}

}














